package com.kitty.game.player.serializer;

import com.kitty.game.role.model.Role;
import com.kitty.game.task.model.user.RoleTask;
import com.kitty.game.utils.JsonUtils;
import org.apache.commons.lang3.StringUtils;

public class RoleTaskSerializer implements IPlayerPropSerializer{
    @Override
    public void serialize(Role player) {
        if (player.getTask() != null) {
            player.setTaskJson(JsonUtils.object2String(player.getTask()));
        }
    }

    @Override
    public void deserialize(Role player) {
        String json = player.getTaskJson();
        if (StringUtils.isNotEmpty(json)) {
            player.setTask(JsonUtils.string2Object(json, RoleTask.class));
        }
    }
}
